<%--
  Created by IntelliJ IDEA.
  User: Stiofan
  Date: 2016/12/15
  Time: 18:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/common/tags.jsp" %>

<aos:html title="土地基础信息采集" base="http" lib="ext">
    <aos:body>
    </aos:body>
</aos:html>
<aos:onready>
    <aos:viewport layout="fit">
        <aos:panel layout="column" columnWidth="1" border="false" autoScroll="true">
            <aos:formpanel id="tdjcxxForm" layout="column" columnWidth="1" autoScroll="true">
                <aos:fieldset title="土地基础信息采集" collapsible="false">
                    <aos:combobox id="isYz" name="isYz" fieldLabel="是否有证" value="true" columnWidth="0.25"
                                  dicField="isYzDm" onselect="fn_isYz" star="true" allowBlank="false"/>
                    <aos:textfield id="tdzdh" name="tdzdh" fieldLabel="宗地地号" columnWidth="0.25"
                                   onenterkey="queryTdjcxx"/>
                    <aos:textfield id="tdbh" name="tdbh" fieldLabel="土地编号" columnWidth="0.25" onenterkey="queryTdjcxx"/>
                    <aos:textfield id="tdzmj" name="tdzmj" fieldLabel="土地面积(平米)" columnWidth="0.25" readOnly="true"/>
                    <aos:combobox id="tdxzDm" name="tdxzDm" dicField="tdxzDm" fieldLabel="土地性质" columnWidth="0.25"
                                  star="true" allowBlank="false"/>
                    <aos:combobox id="tdytDm" name="tdytDm" dicField="tdytDm" fieldLabel="土地用途" columnWidth="0.25"
                                  star="true" allowBlank="false"/>
                    <aos:textfield id="tdzyz" name="tdzyz" fieldLabel="土地原值(元)" columnWidth="0.25" readOnly="true"/>
                </aos:fieldset>
                <aos:fieldset title="土地边界四至" collapsible="false">
                    <aos:textfield name="tdbjszD" fieldLabel="东" columnWidth="0.5"/>
                    <aos:textfield name="tdbjszX" fieldLabel="西" columnWidth="0.5"/>
                    <aos:textfield name="tdbjszN" fieldLabel="南" columnWidth="0.5"/>
                    <aos:textfield name="tdbjszB" fieldLabel="北" columnWidth="0.5"/>
                </aos:fieldset>
                <aos:fieldset title="坐落地址" collapsible="false">
                    <aos:hiddenfield id="xzqhdsDm" name="xzqhdsDm" fieldLabel="所属地市" columnWidth="0.25"
                                     value="620500" star="true" allowBlank="false"/>
                    <aos:combobox id="xzqhxqDm" name="xzqhxqDm" fieldLabel="所属县区" columnWidth="0.25"
                                  url="tdjcxxcjService.queryXzqhszDmBySjxzqhszDm" onselect="queryJdxzDmByXzqhszDm"
                                  star="true" allowBlank="false"/>
                    <aos:combobox id="jdxzDm" name="jdxzDm" fieldLabel="街道(乡镇)"
                                  url="tdjcxxcjService.queryJdxzDmByXzqhszDm"
                                  columnWidth="0.25" onselect="querySqjqDmByJdxzDm" star="true" allowBlank="false"/>
                    <aos:combobox id="zldzSqjqDm" name="zldzSqjqDm" fieldLabel="所属街(路、村)" columnWidth="0.25"
                                  url="tdjcxxcjService.querySqjqDmByJdxzDm" onselect="queryDlxdDmBySqjqDm" star="true"
                                  allowBlank="false"/>
                    <aos:combobox id="zldzDlxdDm" name="zldzDlxdDm" fieldLabel="所属巷道" columnWidth="0.25"
                                  url="tdjcxxcjService.queryDlxdDmBySqjqDm"/>
                    <aos:textfield id="zldzLh" name="zldzLh" fieldLabel="所属路号" columnWidth="0.25"/>
                </aos:fieldset>
                <aos:fieldset title="土地等级信息采集" collapsible="false">
                    <aos:gridpanel id="tdjcmxxxGrid" layout="fit" hidePagebar="true" forceFit="true" columnWidth="1"
                                   url="tdjcxxcjService.queryTdjcmxxxByTdbh" onitemdblclick="openTdjcmxxxWin"
                                   features="summary">
                        <aos:selmodel type="checkbox" mode="single"/>
                        <aos:column header="土地等级明细UUID" dataIndex="tddjmxuuid" hidden="true"/>
                        <aos:column header="土地等级" dataIndex="tddjDm" rendererField="tddjDm" align="center"
                                    summaryRenderer="function(){return '合计'}"/>
                        <aos:column header="单位税额标准代码" dataIndex="dwseDm" hidden="true"/>
                        <aos:column header="税额标准" dataIndex="sebz" align="center"/>
                        <aos:column header="土地面积(平米)" dataIndex="tdmj" type="number" format="0.00" summaryType="sum"/>
                        <aos:column header="土地原值(元)" dataIndex="tdyz" type="number" format="0.00" summaryType="sum"/>
                        <aos:column header="应纳税额(元)" dataIndex="ynse" type="number" format="0.00" summaryType="sum"/>
                        <aos:docked columnWidth="1">
                            <aos:dockeditem id="btnGridAdd" text="新增" onclick="openTdjcmxxxWin" icon="ok.png"/>
                            <aos:dockeditem id="btnGridDel" text="删除" onclick="openZfTdjcxxMxWin" icon="del.png"/>
                        </aos:docked>
                    </aos:gridpanel>
                </aos:fieldset>
            </aos:formpanel>
            <aos:window id="tdjcmxxxWin" title="土地等级明细信息" width="1000" maxHeight="460">
                <aos:formpanel id="tdjcmxxxForm" layout="column" autoScroll="true">
                    <aos:hiddenfield id="tddjmxuuid" name="tddjmxuuid"/>
                    <aos:combobox id="tddjDm" name="tddjDm" fieldLabel="土地等级" labelWidth="90" columnWidth="1"
                                  url="tdjcxxcjService.queryTddjDmByXzqhxzDm" onselect="querySebzByXzqhszDmAndTddjDm" star="true"
                                  allowBlank="false"/>
                    <aos:combobox id="dwseDm" name="dwseDm" fieldLabel="税额标准" labelWidth="90" columnWidth="1"
                                  url="tdjcxxcjService.querySebzByXzqhxzDm" onselect="calcTdynse" star="true"
                                  allowBlank="false"/>
                    <aos:textfield id="tdmj" name="tdmj" fieldLabel="土地面积(平米)" labelWidth="90" columnWidth="1"
                                   onblur="calcTdynse" regex="/^[0-9]+([.]{1}[0-9]{1,2})?$/"
                                   regexText="必输输入数字并且保留至多两位小数"
                                   msgTarget="under" star="true" allowBlank="false"/>
                    <aos:textfield id="tdyz" name="tdyz" fieldLabel="土地原值(元)" labelWidth="90" columnWidth="1"
                                   onblur="calcTdynse" regex="/^[0-9]+([.]{1}[0-9]{1,2})?$/"
                                   regexText="必输输入数字并且保留至多两位小数"
                                   msgTarget="under" star="true" allowBlank="false"/>
                    <aos:textfield id="ynse" name="ynse" fieldLabel="应纳税额(元)" labelWidth="90" columnWidth="1"
                                   readOnly="true"
                                   regex="/^[0-9]+([.]{1}[0-9]{1,2})?$/" regexText="必输输入数字并且保留至多两位小数"
                                   msgTarget="under" star="true" allowBlank="false"/>
                    <aos:docked dock="bottom" ui="footer">
                        <aos:dockeditem xtype="tbfill"/>
                        <aos:dockeditem id="btnDockSave" text="保存" onclick="saveTdjcmxxxByTdbh" icon="ok.png"/>
                        <aos:dockeditem text="关闭" onclick="#tdjcmxxxWin.close();" icon="close.png"/>
                    </aos:docked>
                </aos:formpanel>
            </aos:window>
            <aos:window id="zfTdjcxxWin" title="作废土地基础信息" width="1000" maxHeight="460">
                <aos:formpanel id="zfTdjcxxForm" layout="column" autoScroll="true">
                    <aos:textareafield id="zfyy" name="zfyy" fieldLabel="作废原因" labelWidth="60" columnWidth="1"
                                       height="200"/>
                    <aos:docked dock="bottom" ui="footer">
                        <aos:dockeditem xtype="tbfill"/>
                        <aos:dockeditem text="作废" onclick="zfTdjcxxByTdbh" icon="del.png"/>
                        <aos:dockeditem text="关闭" onclick="#zfTdjcxxWin.close();" icon="close.png"/>
                    </aos:docked>
                </aos:formpanel>
            </aos:window>
            <aos:window id="zfTdjcxxMxWin" title="作废土地基础明细信息" width="1000" maxHeight="460">
                <aos:formpanel id="zfTdjcxxMxForm" layout="column" autoScroll="true">
                    <aos:textareafield id="zfyyMx" name="zfyyMx" fieldLabel="作废原因" labelWidth="60" columnWidth="1"
                                       height="200"/>
                    <aos:docked dock="bottom" ui="footer">
                        <aos:dockeditem xtype="tbfill"/>
                        <aos:dockeditem text="作废" onclick="zfTdjcxxMxByTdsymxuuid" icon="del.png"/>
                        <aos:dockeditem text="关闭" onclick="#zfTdjcxxMxWin.close();" icon="close.png"/>
                    </aos:docked>
                </aos:formpanel>
            </aos:window>
            <aos:docked dock="bottom" ui="footer" columnWidth="1" layout="column" border="false">
                <aos:panel layout="column" columnWidth="1" border="false">
                    <aos:panel layout="column" columnWidth="0.5" center="true" animate="false" border="false">
                        <aos:button text="查询" columnWidth="0.25" margin="0 5" onclick="queryTdjcxx"/>
                        <aos:button id="btnSave" text="保存" columnWidth="0.25" margin="0 5" onclick="saveTdjcxx"/>
                        <aos:button id="btnZf" text="作废" columnWidth="0.25" margin="0 5"
                                    onclick="#zfTdjcxxWin.show();"/>
                        <aos:button text="重置" columnWidth="0.25" margin="0 5" onclick="resetTdjcxxForm"/>
                    </aos:panel>
                </aos:panel>
            </aos:docked>
        </aos:panel>
    </aos:viewport>
    <script type="text/javascript">
        function queryTdjcxx() {
            if (tdzdh.getValue() === "" && tdbh.getValue() === "") {
                AOS.err("必须输入宗地地号、土地编号其中一项进行查询");
            } else {
                if (tdzdh.getValue() !== "" && tdbh.getValue() === "") {
                } else if (tdzdh.getValue() === "" && tdbh.getValue() !== "") {
                } else {
                    AOS.err("仅能通过宗地地号、土地编号其中一项进行查询");
                    return;
                }
                var params = {
                    tdzdh: tdzdh.getValue(),
                    tdbh: tdbh.getValue()
                };
                AOS.ajax({
                    params: params,
                    url: "tdjcxxcjService.queryTdjcxx",
                    ok: function (data) {
                        if (data.appcode === "noTdjcxx") {
                            AOS.tip("未查询到相关信息，可以进行土地基础信息采集!");
                            queryXzqhszDmBySjxzqhszDm();
                            Ext.getCmp("btnSave").setDisabled(false);
                            Ext.getCmp("btnZf").setDisabled(true);
                            Ext.getCmp("btnGridAdd").setDisabled(true);
                            Ext.getCmp("btnGridDel").setDisabled(true);
                            AOS.read(tdzdb);
                            AOS.read(tdbh);
                        } else {
                            if (data.appcode === "war") {
                                AOS.warn(data.appmsg);//提示无权操作
                                Ext.getCmp("btnSave").setDisabled(true);
                                AOS.edit(tdzdb);
                                AOS.edit(tdbh);
                            } else if (data.appcode === "err") {
                                AOS.err(data.appmsg);//提示需要调整管理员
                                Ext.getCmp("btnSave").setDisabled(true);
                                AOS.edit(tdzdh);
                                AOS.edit(tdbh);
                            }
                            else {
                                AOS.tip("查询到相关信息，可以进行土地基础信息修改!");
                                Ext.getCmp("btnSave").setDisabled(false);
                                Ext.getCmp("btnZf").setDisabled(false);
                                Ext.getCmp("btnGridAdd").setDisabled(false);
                                Ext.getCmp("btnGridDel").setDisabled(false);
                                AOS.read(tdzdh);
                                AOS.read(tdbh);
                            }
                            queryXzqhszDmBySjxzqhszDm();
                            AOS.setValues(tdjcxxForm, data);
                            queryJdxzDmByXzqhszDm();
                            AOS.setValues(tdjcxxForm, data);
                            querySqjqDmByJdxzDm();
                            AOS.setValues(tdjcxxForm, data);
                            queryTdjcmxxxByTdbh();
                        }

                    }
                });
            }
        }
        function saveTdjcxx() {
            if (AOS.valid(tdjcxxForm)) {
                AOS.ajax({
                    forms: tdjcxxForm,
                    url: "tdjcxxcjService.saveTdjcxx",
                    ok: function (data) {
                        Ext.getCmp("btnSave").setDisabled(false);
                        if (data.appcode === "suc") {
                            AOS.tip("土地基础信息保存成功!");
                            AOS.setValues(tdjcxxForm, data);
                            Ext.getCmp("btnSave").setDisabled(true);
                            queryTdjcmxxxByTdbh();
                            Ext.getCmp("btnGridAdd").setDisabled(false);
                            Ext.getCmp("btnGridDel").setDisabled(false);
                        } else {
                            AOS.err(data.appmsg);
                        }

                    }
                });
            } else {
                AOS.err("请检查相关信息是否输入完整！");
            }
        }
        function resetTdjcxxForm() {
            AOS.reset(tdjcxxForm);
            AOS.edit(tdzdh);
            AOS.edit(tdbh);
            Ext.getCmp("btnGridAdd").setDisabled(true);
            Ext.getCmp("btnGridDel").setDisabled(true);
            Ext.getCmp("btnSave").setDisabled(true);
            tdjcmxxxGrid_store.removeAll();
        }
        function queryXzqhszDmBySjxzqhszDm() {
            var sjxzqhsz_dm = "620500";
            var params = {
                sjxzqhszDm: sjxzqhsz_dm
            };
            xzqhxqDm_store.getProxy().extraParams = params;
            xzqhxqDm_store.reload();
        }
        function queryJdxzDmByXzqhszDm() {
            var xzqhsz_dm = xzqhxqDm.getValue();
            var params = {
                xzqhszDm: xzqhsz_dm
            };
            jdxzDm_store.getProxy().extraParams = params;
            jdxzDm_store.reload();
            queryTddjDmByXzqhxzDm();
        }
        function querySqjqDmByJdxzDm() {
            var jdxzDm = Ext.getCmp("jdxzDm").getValue();
            var params = {
                jdxzDm: jdxzDm
            };
            zldzSqjqDm_store.getProxy().extraParams = params;
            zldzSqjqDm_store.reload();
        }
        function queryDlxdDmBySqjqDm() {
            var sqjqDm = Ext.getCmp("zldzSqjqDm").getValue();
            var params = {
                sqjqDm: sqjqDm
            };
            zldzDlxdDm_store.getProxy().extraParams = params;
            zldzDlxdDm_store.reload();
        }
        function queryTdjcmxxxByTdbh() {
            var params = {
                tdbh: tdbh.getValue()
            };
            tdjcmxxxGrid_store.getProxy().extraParams = params;
            tdjcmxxxGrid_store.reload();
            var tdzmj = 0;
            var tdzyz = 0;
            for (var i = 0; i < tdjcmxxxGrid_store.getCount(); i++) {
                var record = tdjcmxxxGrid_store.getAt(i);
                tdzmj += record.data.tdmj;
                tdzyz += record.data.tdyz;
            }
            AOS.setValue("tdzmj", tdzmj);
            AOS.setValue("tdzyz", tdzyz);
        }
        function openTdjcmxxxWin() {
            var rows = AOS.rows(Ext.getCmp("tdjcmxxxGrid"));
            if (rows === 1) {
                var record = AOS.selectone(Ext.getCmp("tdjcmxxxGrid"));
                AOS.setValue("tdjcmxxxForm.tddjmxuuid", record.data.tddjmxuuid);
                AOS.setValue("tdjcmxxxForm.tddjDm", record.data.tddjDm);
                AOS.setValue("tdjcmxxxForm.dwseDm", record.data.dwseDm);
                AOS.setValue("tdjcmxxxForm.tdmj", record.data.tdmj);
                AOS.setValue("tdjcmxxxForm.ynse", record.data.ynse);
            } else {
                AOS.reset(tdjcmxxxForm);
            }
            querySebzByXzqhszDmAndTddjDm();
            Ext.getCmp("btnDockSave").setDisabled(false);
            tdjcmxxxWin.show();

        }
        function querySebzByXzqhszDmAndTddjDm() {
            var xzqhszDm = Ext.getCmp("xzqhxqDm").getValue();
            var tddjDm = Ext.getCmp("tddjDm").getValue();
            var params = {
                xzqhszDm: xzqhszDm,
                tddjDm: tddjDm
            };
            dwseDm_store.getProxy().extraParams = params;
            dwseDm_store.reload();
        }
        function saveTdjcmxxxByTdbh() {
            if (AOS.valid(tdjcmxxxForm)) {
                var params = {
                    tdbh: tdbh.getValue(),
                    sebz: Ext.getCmp("dwseDm").getRawValue()
                };
                AOS.ajax({
                    params: params,
                    forms: tdjcmxxxForm,
                    url: "tdjcxxcjService.saveTdjcmxxxByTdbh",
                    ok: function (data) {
                        if (data.appcode === "suc") {
                            AOS.tip("土地等级信息保存成功!");
                            tdjcmxxxWin.close();
                            queryTdjcmxxxByTdbh();
                            Ext.getCmp("btnDockSave").setDisabled(true);
                        } else if(data.appcode==="err") {
                            AOS.err("土地等级信息保存失败!");
                        }
                    }
                });
            } else {
                AOS.err("请检查相关信息是否输入完整！");
            }
        }
        function calcTdynse() {
            var sebz = Ext.getCmp("dwseDm").getRawValue();
            var tdmj = Ext.getCmp("tdmj").getValue();
            Ext.getCmp("ynse").setValue(sebz * tdmj);
        }
        function fn_isYz() {
            var tmpIsYz = isYz.getValue();
            resetTdjcxxForm();
            if (tmpIsYz === "true") {
                AOS.edit(tdzdh);
            } else {
                AOS.read(tdzdh);
                tdzdh.setValue("");
                queryXzqhszDmBySjxzqhszDm();
                Ext.getCmp("btnSave").setDisabled(false);
                queryXzqhszDmBySjxzqhszDm();
            }
            isYz.setValue(tmpIsYz);
        }
        function zfTdjcxxByTdbh() {
            if (AOS.valid(zfTdjcxxForm)) {
                var params = {
                    tdbh: Ext.getCmp("tdbh").getValue()
                };
                AOS.ajax({
                    params: params,
                    forms: zfTdjcxxForm,
                    url: "tdjcxxcjService.zfTdjcxxByTdbh",
                    ok: function (data) {
                        if (data.appcode === "suc") {
                            AOS.tip("此土地信息及相关土地明细信息成功作废!");
                            btnSave.disabled = true;
                        } else if (data.appcode === "err") {
                            AOS.err(data.appmsg);
                        }
                        zfTdjcxxWin.close();
                    }
                });
            } else {
                AOS.err("请检查相关信息是否输入完整！");
            }
        }
        function openZfTdjcxxMxWin() {
            var rows = AOS.rows(Ext.getCmp("tdjcmxxxGrid"));
            if (rows === 1) {
                zfTdjcxxMxWin.show();
            }
        }
        function zfTdjcxxMxByTdsymxuuid() {
            if (AOS.valid(zfTdjcxxMxForm)) {
                var record = AOS.selectone(Ext.getCmp("tdjcmxxxGrid"));
                var params = {
                    tddjmxuuid: record.data.tddjmxuuid
                };
                AOS.ajax({
                    params: params,
                    forms: zfTdjcxxMxForm,
                    url: "tdjcxxcjService.zfTdjcxxMxByTdsymxuuid",
                    ok: function (data) {
                        if (data.appcode === "suc") {
                            AOS.tip("选中的土地明细信息成功作废!");
                        } else if (data.appcode === "err") {
                            AOS.err(data.appmsg);
                        }
                        zfTdjcxxMxWin.close();
                        tdjcmxxxGrid_store.reload();
                    }
                });
            } else {
                AOS.err("请检查相关信息是否输入完整！");
            }
        }
        function queryTddjDmByXzqhxzDm() {
            var params={
                xzqhszDm:Ext.getCmp("xzqhxqDm").getValue()
            };
            tddjDm_store.getProxy().extraParams = params;
            tddjDm_store.reload();
        }
    </script>
    Ext.getCmp("btnGridAdd").setDisabled(true);
    Ext.getCmp("btnGridDel").setDisabled(true);
    Ext.getCmp("btnSave").setDisabled(true);
    Ext.getCmp("btnZf").setDisabled(true);
</aos:onready>